import { createStore } from "vuex";
import { getToken, setToken } from "../../utils/auth";
import { Menu } from "../../types/utils.interface";
import { loginfuc } from "../../service/login";
export default createStore({
  state: {
    RouterList: [],
    init: false,
    token: getToken() as any,
    sider: [] as Menu[],
    roles: [],
    user: {},
  },
  mutations: {
    set_router: (state, RouterList) => {
      state.RouterList = RouterList;
    },
    set_init: (state, init) => {
      state.init = init;
    },
    set_sider: (state, sider: Menu[]) => {
      state.sider = sider;
    },
    set_token: (state, token) => {
      state.token = token;
    },
  },
  actions: {
    login: async ({ commit }, userinfo) => {
      const data = await loginfuc(userinfo);
      const token = data.data.token.token;
      setToken(token);
      commit("set_token", token);
      return data;
    },
  },
  modules: {},
});
